using System;
using System.ComponentModel;
using System.Reflection;

namespace BW.MesProject.Equipment.Domain.Extensions
{
    /// <summary>
    /// 枚举扩展方法
    /// </summary>
    public static class EnumExtensions
    {
        /// <summary>
        /// 获取枚举的Description特性值
        /// </summary>
        /// <param name="value">枚举值</param>
        /// <returns>Description特性值，如果没有则返回枚举名称</returns>
        public static string GetDescription(this System.Enum value)
        {
            FieldInfo field = value.GetType().GetField(value.ToString());
            
            if (field?.GetCustomAttributes(typeof(DescriptionAttribute), false) is DescriptionAttribute[] attributes && attributes.Length > 0)
            {
                return attributes[0].Description;
            }
            
            return value.ToString();
        }
    }
} 